﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;


namespace OpenLightGroup.Common
{
    /// <summary>
    /// Holds static extensions for the ObservableCollection type.
    /// </summary>
    public static class ObservableCollectionExtensions
    {

        /// <summary>
        /// Adds the list of items to the current ObservalbeCollection.
        /// </summary>
        /// <typeparam name="T">The type of item to add.</typeparam>
        /// <param name="collection">The current observable collection.</param>
        /// <param name="items">The items to add.</param>
        public static void AddRange<T>(this ObservableCollection<T> collection, IEnumerable<T> items)
        {
            if (collection == null)
             throw new ArgumentException("Collection cannot be null", "collection");

           if(items == null)
               throw new ArgumentException("Items cannot be null", "items");

            foreach (var item in items)
                collection.Add(item);

        }

        /// <summary>
        /// Creates an observable collection from any IEnumerable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">The items.</param>
        /// <returns></returns>
        public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> items)
        {
            if (items == null)
                throw new ArgumentException("Items cannot be null", "items");

            var output = new ObservableCollection<T>();

            output.AddRange(items);

            return output;

        }
    }
}
